package com.example.pinkcat.activity.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.PagerAdapter;


import com.example.pinkcat.R;
import com.example.pinkcat.activity.api.getData.GetData;
import com.example.pinkcat.activity.pinkCatUser.userStaticMsg;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class VAMF_viewpager_adapter extends PagerAdapter {
    private Context context;
    private String[] titles;
    private ArrayList<View> views;  //每个选项卡对应的布局



    public VAMF_viewpager_adapter(String[] titles, ArrayList<View> views, Context context){
        this.titles=titles;
        this.views=views;
        this.context=context;
    }

    //实例化选项卡
    @NotNull
    @SuppressLint("ShowToast")
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View v = views.get(position);
        container.addView(v);

        //
        TextView textView=v.findViewById(R.id.text_sort_way);
        textView.setText(R.string.viewState);
        //所有页面布局一样
        RecyclerView recyclerView=v.findViewById(R.id.recyceleview_searchvideo);
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        VAMF_recyleview_adapter adapter;
        adapter = new VAMF_recyleview_adapter(context, 10, 0);
        recyclerView.setAdapter(adapter);
        //获取数据
        GetData.getMyVideo(context,adapter,position, userStaticMsg.userId);

        Spinner spinner=(Spinner) v.findViewById(R.id.Sort_select);
        List<String> list = new ArrayList<String>();
            list.add("在看");
            list.add("看过");
        ArrayAdapter<String> spinner_adapter=new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item,list);
        spinner_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(spinner_adapter);



        return v;
    }

    //删除选项卡
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(views.get(position));
    }
    //返回选项大小
    @Override
    public int getCount() {
        return views.size();
    }

    //判断是否是为返回选项卡
    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view==object;
    }

    //获取标题
    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }
}
